/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : Network_Setup.c /Project:AVOS		       **
**        Revision : 1.1                                       	**
**                                                             	**
*****************************************************************/
#ifdef ENABLE_NETWORK
#include "../menu.h"
#include "Network_SetupEvent.h"
#include "Network_Setup.h"
#include "../resource_network/network_icon_date.h"

INT32S Network_SetupMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return Network_SetupOnShow(hwnd, lpParam) ;
        case WM_KEYDOWN:
            return Network_SetupOnKeyPress(hwnd, lpParam) ;
    }
    return 0 ;
}

void SetNetwork_SetupPalette(void)
{
   YUVENTRY mask_para[4] = {0,79,4095,4095};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 16392,0x8000 | 21176,0x8000 | 17752,0x8000 | 16392,17592,19496,19832,19656,19992,18104,17673,17817,15864,15721,15912,16344};
    AWSetPalette(0,16, palette_para);
    return ;
}

void SetNetwork_SetupPos(HWND* pControl, INT8U CurOsdSize)
{
  
            RECT StandardWindowRect = {0,0,800,480};
            pControl->winrect = StandardWindowRect;
            CREATEWINDOWPARAM StandardWindowPara = {1,{{0,0,800,480},    {0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},    SetNetwork_SetupPalette};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&StandardWindowPara);
           
    return;
}

HWND *CreateControlNetwork_Setup(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
  
            CREATEWINDOWPARAM Standardwindow_para = {1,{{0,0,800,480},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetNetwork_SetupPalette};
            //Create Menu Window -- 1
            pNewControl = AWCreateWinControl("TWindow","Network_Setup",WS_OVERLAPPEDWINDOW,
		                      0,0,800,480,NULL, (INT32S)&Standardwindow_para,Network_SetupMsgProc) ;
            pNewControl->win_id = 0 ;
          
            return pNewControl;
}

void SetManuScanPos(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
   
            pControl->winrect.top = pControl->parent->winrect.top + 80;
            pControl->winrect.left = pControl->parent->winrect.left + 50;
            pControl->winrect.width = 700;
            pControl->winrect.height = 340;
            pControl->draw_info_num = 11;
            RECT StandardDrawRect[11] = {
            {pControl->winrect.left + 40,pControl->winrect.top + 20,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 26,230,25},
            {pControl->winrect.left + 380,pControl->winrect.top + 26,200,28},
            {pControl->winrect.left + 40,pControl->winrect.top + 50,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 56,230,28},
            {pControl->winrect.left + 380,pControl->winrect.top + 56,200,28},
            {pControl->winrect.left + 40,pControl->winrect.top + 80,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 86,230,28},
            {pControl->winrect.left + 380,pControl->winrect.top + 86,200,28},
            {pControl->winrect.left + 40,pControl->winrect.top + 110,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 116,230,28},
            
            };
            for(iLoop=0; iLoop < 11; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &StandardDrawRect[iLoop], sizeof(RECT));
            
    return;
}

INT32S ManuScanMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return ManuScanOnShow(hwnd, lpParam) ;
        case WM_KEYDOWN:
            return ManuScanOnKeyPress(hwnd, lpParam) ;
    }
    return 0 ;
}

HWND *CreateControlManuScan(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- ManuScan
    HWND *pNewControl;
    
            pNewControl = AWCreateWinControl("TControl","ManuScan",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      50,80,700,340,pParent,0,ManuScanMsgProc) ;
            pNewControl->win_id = 1 ;
            pNewControl->draw_info_num = 11;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO StandardDrawDatas[11] = {
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_SELECT_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)SSID_STR,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)APNAME_STR[0],DT_STRING_DATA},
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)SECURYTY_STR,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)SECURYTY_STR_OPEN,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)IPADDRESS_STR,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)IPADDRESS_STR_AUTO,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)CONNECT_STR,DT_RESOURCE_STRING_DATA}
                          
                          };
            memcpy(pNewControl->draw_info,StandardDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
           
            return pNewControl;
}

void SetCaption_SetPos(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;

            pControl->winrect.top = pControl->parent->winrect.top + 0;
            pControl->winrect.left = pControl->parent->winrect.left + 0;
            pControl->winrect.width = 800;
            pControl->winrect.height = 78;
            pControl->draw_info_num = 3;
            RECT StandardDrawRect[3] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,136,78},
            {pControl->winrect.left + 600,pControl->winrect.top + 48,100,30},
            {pControl->winrect.left + 600,pControl->winrect.top + 48,100,28},
            };
            for(iLoop=0; iLoop < 3; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &StandardDrawRect[iLoop], sizeof(RECT));
          
    return;
}

INT32S Caption_SetMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return Caption_SetOnShow(hwnd, lpParam) ;
    }
    return 0 ;
}

HWND *CreateControlCaption_Set(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- Caption_Set
    HWND *pNewControl;
  
            pNewControl = AWCreateWinControl("TControl","Caption_Set",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      0,0,800,78,pParent,0,Caption_SetMsgProc) ;
            pNewControl->win_id = 2 ;
            pNewControl->draw_info_num = 3;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO StandardDrawDatas[3] = {
                          {0,0,0,0,(INT32U)ICON_NETWORK_ICON,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)MANUAL_SETTING,DT_RESOURCE_STRING_DATA}};
            memcpy(pNewControl->draw_info,StandardDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
          
            return pNewControl;
}

void SetScan_resultPos(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;

            pControl->winrect.top = pControl->parent->winrect.top + 80;
            pControl->winrect.left = pControl->parent->winrect.left + 50;
            pControl->winrect.width = 700;
            pControl->winrect.height = 340;
            pControl->draw_info_num = 12;
            RECT StandardDrawRect[12] = {
            {pControl->winrect.left + 40,pControl->winrect.top + 20,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 26,230,25},       
            {pControl->winrect.left + 40,pControl->winrect.top + 50,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 56,230,28},   
            {pControl->winrect.left + 40,pControl->winrect.top + 80,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 86,230,28},        
            {pControl->winrect.left + 40,pControl->winrect.top + 110,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 116,230,28},
            {pControl->winrect.left + 40,pControl->winrect.top + 140,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 146,230,28},
            {pControl->winrect.left + 40,pControl->winrect.top + 170,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 176,230,28},
            
             };
            for(iLoop=0; iLoop < 12; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &StandardDrawRect[iLoop], sizeof(RECT));

    return;
}

INT32S Scan_resultMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return Scan_resultOnShow(hwnd, lpParam) ;
        case WM_KEYDOWN:
            return Scan_resultOnKeyPress(hwnd, lpParam) ;
        case WM_PAINT:
            return Scan_resultOnPaint(hwnd, lpParam) ;    
    }
    return 0 ;
}

HWND *CreateControlScan_result(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- Scan_result
    HWND *pNewControl;
 
            pNewControl = AWCreateWinControl("TControl","Scan_result",(WS_CHILDWINDOW | WS_DISVISIBLE),
		                      0,0,60,40,pParent,0,Scan_resultMsgProc) ;
            pNewControl->win_id = 3 ;
            pNewControl->draw_info_num = 12;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO StandardDrawDatas[12] = {
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_SELECT_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)APNAME_STR[0],DT_STRING_DATA},                         
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)APNAME_STR[1],DT_STRING_DATA},
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)APNAME_STR[2],DT_STRING_DATA},
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)APNAME_STR[3],DT_STRING_DATA},                         
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)APNAME_STR[4],DT_STRING_DATA},
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)APNAME_STR[5],DT_STRING_DATA},
                        };
            memcpy(pNewControl->draw_info,StandardDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;

            return pNewControl;
}

void SetInternet_SettingPos(HWND* pControl, INT8U CurOsdSize)
{
  int iLoop;
   
            pControl->winrect.top = pControl->parent->winrect.top + 80;
            pControl->winrect.left = pControl->parent->winrect.left + 50;
            pControl->winrect.width = 700;
            pControl->winrect.height = 340;
            pControl->draw_info_num = 11;
            RECT StandardDrawRect[11] = {
            {pControl->winrect.left + 40,pControl->winrect.top + 20,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 26,230,25},
            {pControl->winrect.left + 380,pControl->winrect.top + 26,200,28},
            {pControl->winrect.left + 40,pControl->winrect.top + 50,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 56,230,28},
            {pControl->winrect.left + 380,pControl->winrect.top + 56,200,28},
            {pControl->winrect.left + 40,pControl->winrect.top + 80,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 86,230,28},
            {pControl->winrect.left + 380,pControl->winrect.top + 86,200,28},
            {pControl->winrect.left + 40,pControl->winrect.top + 110,620,30},
            {pControl->winrect.left + 60,pControl->winrect.top + 116,230,28},
            
            };
            for(iLoop=0; iLoop < 11; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &StandardDrawRect[iLoop], sizeof(RECT));
            
    return;
}

INT32S Internet_SettingMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return Internet_SettingOnShow(hwnd, lpParam) ;
        case WM_PAINT:
            return Internet_SettingOnPaint(hwnd, lpParam) ;
        case WM_KEYDOWN:
            return Internet_SettingOnKeyPress(hwnd, lpParam) ;
    }
    return 0 ;
}

HWND *CreateControlInternet_Setting(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- Internet_Setting
    HWND *pNewControl;

            pNewControl = AWCreateWinControl("TControl","Internet_Setting",(WS_CHILDWINDOW | WS_DISVISIBLE),
		                        50,80,700,340,pParent,0,Internet_SettingMsgProc) ;
            pNewControl->win_id = 4 ;
            pNewControl->draw_info_num = 11;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO StandardDrawDatas[11] = {
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_SELECT_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)URL_STR,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)internet_setting[0],DT_STRING_DATA},
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)PASSWORD_STR,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)internet_setting[1],DT_STRING_DATA},
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)CONNECT_MODE_STR,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)INTER_AUTO_STR,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)ICON_NET_SETUP_BAR,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)CONNECT_STR,DT_RESOURCE_STRING_DATA}
                          };
            memcpy(pNewControl->draw_info,StandardDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
           
            return pNewControl;
}

HWND* CreateMenuNetwork_Setup(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pNetwork_Setup = CreateControlNetwork_Setup(NULL,CurrentOsdSize);
    SetNetwork_SetupPos(pNetwork_Setup,CurrentOsdSize);

    pNewControl= CreateControlManuScan(pNetwork_Setup,CurrentOsdSize);
    SetManuScanPos(pNewControl,CurrentOsdSize);

    pNewControl= CreateControlCaption_Set(pNetwork_Setup,CurrentOsdSize);
    SetCaption_SetPos(pNewControl,CurrentOsdSize);

    pNewControl= CreateControlScan_result(pNetwork_Setup,CurrentOsdSize);
    SetScan_resultPos(pNewControl,CurrentOsdSize);

    pNewControl= CreateControlInternet_Setting(pNetwork_Setup,CurrentOsdSize);
    SetInternet_SettingPos(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pNetwork_Setup;
    pWin->pFocusControl = AWFindWinCtrlByName("ManuScan");
    return pNetwork_Setup;
}

void WinResetNetwork_SetupControlsPos(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://Network_Setup
            SetNetwork_SetupPos(pControl,CurOsdSize) ;
            break ;
        case 1://ManuScan
            SetManuScanPos(pControl,CurOsdSize) ;
            break ;
        case 2://Caption_Set
            SetCaption_SetPos(pControl,CurOsdSize) ;
            break ;
        case 3://Scan_result
            SetScan_resultPos(pControl,CurOsdSize) ;
            break ;
        case 4://Internet_Setting
            SetInternet_SettingPos(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetNetwork_SetupPos(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("Network_Setup");
    if(pControl == NULL) return ;

    WinResetNetwork_SetupControlsPos(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetNetwork_SetupPos(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}

#endif
